#ifndef _CWINDOW_H_
#define _CWINDOW_H_

class CWindow
{
public:
	CWindow(HWND hWnd = NULL)
	{
		m_hWnd = hWnd;
	}

	void Attach(HWND hDlg, int id)
	{

		m_hDlg   = hDlg;
		m_itemId = id;
		m_hWnd   = GetDlgItem(hDlg,id);
		ASSERT(::IsWindow(m_hWnd));
	}

	BOOL EnableWindow(BOOL bEnable = TRUE)
	{
		ASSERT(::IsWindow(m_hWnd));
		return ::EnableWindow(m_hWnd, bEnable);
	}

	BOOL ShowWindow(int nCmdShow)
	{
		ASSERT(::IsWindow(m_hWnd));
		return ::ShowWindow(m_hWnd, nCmdShow);
	}

	HWND SetFocus()
	{
		ASSERT(::IsWindow(m_hWnd));
		return ::SetFocus(m_hWnd);
	}

	HWND GetParent() const
	{
		ASSERT(::IsWindow(m_hWnd));
		return ::GetParent(m_hWnd);
	}

	int GetWindowTextLength() const
	{
		ASSERT(::IsWindow(m_hWnd));
		return ::GetWindowTextLength(m_hWnd);
	}

	int GetWindowText(LPTSTR lpszStringBuf, int nMaxCount) const
	{
		ASSERT(::IsWindow(m_hWnd));
		return ::GetWindowText(m_hWnd, lpszStringBuf, nMaxCount);
	}

	BOOL SetWindowText(LPCTSTR lpszString)
	{
		ASSERT(::IsWindow(m_hWnd));
		return ::SetWindowText(m_hWnd, lpszString);
	}

	LRESULT SendMessage(UINT message, WPARAM wParam=0, LPARAM lParam=0)
	{
		ASSERT(::IsWindow(m_hWnd));
		return ::SendMessage(m_hWnd, message, wParam, lParam);
	}

	static LRESULT SendMessage(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
	{
		ASSERT(::IsWindow(hWnd));
		return ::SendMessage(hWnd, message, wParam, lParam);
	}

	BOOL CheckRadioButton(int nIDFirstButton, int nIDLastButton, int nIDCheckButton)
	{
		ASSERT(::IsWindow(m_hWnd));
		return ::CheckRadioButton(m_hWnd, nIDFirstButton, nIDLastButton, nIDCheckButton);
	}

	void CheckButton(BOOL state)
	{
		if ( state )
		{
			CheckDlgButton(m_hDlg,m_itemId,BST_CHECKED);
		} else {
			CheckDlgButton(m_hDlg,m_itemId,BST_UNCHECKED);
		}
	}

	BOOL GetButtonState()
	{
		return (IsDlgButtonChecked(m_hDlg,m_itemId) == BST_CHECKED );
	}

	operator HWND() const { return m_hWnd; }

protected:
	HWND m_hDlg;
	HWND m_hWnd;
	int  m_itemId;  
};

#endif

